Xbasic

Repetition Characters in Regular Expressions

Description

Covers the special characters {n}, {n,}, {n,m}, ?, *, and +

Special Characters

{n}

  • Match n of the previous item

    a{3} matches aaa

{n,}

  • Match n or more of the previous item

    a{1,} matches aa, aaa, aaaa, etc.

{n,m}

  • Match at least n and at most m of the previous item

    a(1,3} matches a, aa, aaa

?

  • Match the previous item zero or one times

    a? matches nothing or a

+

  • Match the previous item one or more times

    a+ matches a, aa, aaa, aaaa, etc.

*

  • Match the previous item zero or more times

    a* matches nothing, a, aa, aaa, aaaa, etc.

Examples

This example looks for a telephone number. The area code must be enclosed in parentheses and there also must be a hyphen.

? regex_split("Our phone number is (781)229-4500.", "(\(\d{3}\)\d{3}-\d{4})")
= "(781)229-4500"

This example looks for the area code telephone number.

? regex_split("Our phone number is (781)229-4500.", "(\(\w{3}\))")
= "(781)"

This example looks for value of a dollar amount.

? regex_split("the price is $123456.78.", "(\d+.\d+)")
= "123456.78"

See Also